<template>
	<view class="main">
		<view :style="'padding-top:'+(demo.height+demo.top+10)+'px'">
			<head1 class="nav_top"
				:style="'height:' +  demo.height + 'px;' + 'padding-top:' + demo.top + 'px;padding-bottom:10px'"
				:nav="title">
			</head1>
		</view>
		<view class="joinReleamain">
			<view class="joinReleamainList">
				<view>
					<view style="display: flex;">
						<text class="titStyle">*职位名称</text>
					</view>
					<input type="text" value="" placeholder="请填写职位名称" v-model="jobForm.postType" />
				</view>
			</view>
			<view class="joinReleamainList" @click="showPCA">
				<view class="dis_flex">
					<view style="display: flex;" :class="jobForm.location==''?'activeTrue':'activeFalse'">
						<text class="titStyle">期望工作地点</text>
					</view>
					<view class="dis_flex">
						<text>{{jobForm.location}}</text><text>></text>
					</view>
				</view>
			</view>
			<view class="joinReleamainList " @click="showCerts">
				<view class="dis_flex">
					<view style="display: flex;">
						<text class="titStyle">证书</text>
					</view>
					<view class="dis_flex common_line selectCerts">
						<text v-if="jobForm.certs==''">请选择证书</text>
						<text v-if="jobForm.certs!=''">{{jobForm.certs}}</text>
						<!-- <text style="display: none;">{{joinForm.certs}}</text> -->
					</view>
				</view>
			</view>
			<view class="joinReleamainList">
				<view class="dis_flex">
					<view style="display: flex;" :class="jobForm.type==''?'activeTrue':'activeFalse'">
						<text class="titStyle">工作性质</text>
					</view>
					<view class="dis_flex common_line">
						<picker @change="gzxzPickerChange" :value="gzxzIndex" :range="gzxz" range-key="meaning">
							<view class="uni-input">{{gzxz[gzxzIndex].meaning}}</view>
						</picker>
						<text>></text>
						<text style="display: none;">{{jobForm.type}}</text>
					</view>
				</view>
			</view>

			<view class="joinReleamainList ">
				<view class="dis_flex">
					<view style="display: flex;" :class="jobForm.salary==''?'activeTrue':'activeFalse'">
						<text class="titStyle">期望薪资范围</text>
					</view>
					<view class="dis_flex common_line">
						<picker @change="salaryPickerChange" :value="salaryIndex" :range="salary" range-key="meaning">
							<view class="uni-input">{{salary[salaryIndex].meaning}}</view>
						</picker>
						<text>></text>
						<text style="display: none;">{{jobForm.salary}}</text>
					</view>
				</view>
			</view>
			<view class="joinReleamainList">
				<view style="display: flex;">
					<text class="titStyle">个人特长</text>
				</view>
				<textarea type="text" value="" v-model="jobForm.specialty" placeholder="介绍工作内容、职位要求、加分项" /></textarea>
			</view>
			<view class="joinReleamainBtn" @click="subForm(jobForm)">保存</view>
		</view>
		<!-- 证书选择 -->
		<view class="selectCert">
			<pca-picker ref="pcaPicker" @confirm="getPCA" @fromChild="getChild"></pca-picker>
		</view>
		<cert v-if="certsIsShow" @getCersList="getcersList" :morenCert='moren'></cert>
	</view>
</template>

<script>
	import head1 from '../../common/head/head'
	import mypick from '../../components/mypick.vue'
	import pcaPicker from "../../components/pcaPicker/pcaPicker.vue"
	import cert from '@/components/lingdang-AddressPicker/AddressPicker.vue'
	export default {
		provide() {
			return {
				updateMoren: this.updateMoren
			}
		},
		components: {
			head1,
			mypick,
			pcaPicker,
			cert
		},
		data() {
			return {
				certsIsShow: false,
				title: '修改求职信息',
				demo: {
					top: '',
					height: ''
				},
					moren: [],
				recruitId: "",
				jobForm: {
					postType: '',
					type: 'jbpart', //jbfull 全职 jbpart 兼职
					location: '四川省-成都市-武侯区',
					salary: '',
					specialty: '',
					certs: ''
				},
				gzxzIndex: 0,
				salaryIndex: 0,
				salary: [], //薪资范围
				postType: '', //职务类型
				// certs:'', //持有证书
				gzxz: [{
					enumId: 0,
					enumValue: 'jbpart',
					meaning: '兼职'
				}, {
					enumId: 1,
					enumValue: 'jbfull',
					meaning: '全职'
				}],
			}
		},
		onLoad(options) {
			this.recruitId = options.data
			this.getDetail(options.data)
		},
		created() {
			const demo = uni.getMenuButtonBoundingClientRect()
			this.demo.top = demo.top
			this.demo.height = demo.height
			this.getSysDict()
		},
		methods: {
			salaryPickerChange: function(e) {
				this.salaryIndex = e.target.value
				for (let i = 0; i < this.salary.length; i++) {
					if (i == this.salaryIndex) {
						this.jobForm.salary = this.salary[i].enumValue
					}
				}
			},
			gzxzPickerChange: function(e) {
				this.gzxzIndex = e.target.value
				for (let i = 0; i < this.gzxz.length; i++) {
					if (i == this.gzxzIndex) {
						this.jobForm.type = this.gzxz[i].enumValue
					}
				}
			},
			// 选择的证书
			getcersList(val) {
				this.jobForm.certs = val
			},
			// 更新证书默认
			updateMoren(data) {
				this.moren = data.split('-')
			},
			showCerts(e) {
				// this.$refs.pcaPicker.show();
				this.certsIsShow = !this.certsIsShow
			},
			// 数据加载
			getSysDict() {
				this.$myResquest.getDict({
					"enumCode": 'salary,job'
				}).then(res => {
					let data = res.data.data
					if (res.data.code == 200) {
						this.salary = data.salary
						this.postType = data.job
						// 设置默认
						this.jobForm.salary = data.salary[0].enumValue
						// this.jobForm.postType = data.job[0].enumValue
						// this.jobForm.certs = data.certs[0].enumValue

					}
				})
			},
			// 获取选择传过来的值
			getChild(child) {
				// this.TJformChange.cert = child
				this.jobForm.location = child
			},
			showPCA(e) {
				this.$refs.pcaPicker.show();
			},
			getPCA(e) {
				console.log(e);
			},
			// 薪资范围
			getSalaryValue(childValue) {
				this.jobForm.salary = childValue
			},
			// // 职务类型
			// getPostTypeValue(childValue) {
			// 	this.jobForm.postType = childValue
			// },
			// 工作性质
			getGzxzValue(childValue) {
				this.jobForm.type = childValue
			},
			// 持有证书
			getCerts(childValue) {
				this.jobForm.certs = childValue
			},
			// 表单提交
			subForm(data) {
				data.recruitId = this.recruitId
				console.log(data)
				let _this = this;
				if (data.postType == '' || data.postType == null) {
					uni.showToast({
						title: '请填写职位名称',
						icon: 'none'
					})
				} else if (data.type == 'jbpart' && data.certs == '') {
					uni.showToast({
						title: "兼职必须选择证书",
						icon: "none"
					})

				} else {
					_this.$myResquest.getJobPut(data).then(res => {
						if (res.data.code == 200) {
							uni.showToast({
								title: "修改成功"
							})
							setTimeout(function() {
								let pages = getCurrentPages()
								// 获取上一页栈
								let prevPage = pages[pages.length - 2]
								prevPage.$vm.test()
								uni.navigateBack()
							}, 1000)
						} else {
							uni.showToast({
								title: "修改失败",
								icon: "none"
							})
							setTimeout(function() {
								uni.navigateBack()
							}, 1000)
						}
					})
				}
			},
			// 获取详情
			getDetail(ids) {
				this.$myResquest.recruitJobDetail({
					recruitId: ids
				}).then(res => {
					if (res.data.code == 200) {
						console.log(res.data.data)
						// // 给表单赋值
						this.jobForm = res.data.data
						// 回显证书
						this.moren = (res.data.data.certs).split('-')
						// // 学历
						// for (let i = 0; i < this.education.length; i++) {
						// 	if (this.education[i].enumValue == this.joinForm.education) {
						// 		this.arrayIndex = i //默认选项
						// 		this.joinForm.education = this.education[i].enumValue
						// 	}
						// }
						// 薪资范围
						for (let i = 0; i < this.salary.length; i++) {
							if (this.salary[i].enumValue == this.jobForm.salary) {
								this.salaryIndex = i //默认选项
								this.jobForm.salary = this.salary[i].enumValue
							}
						}
						// 工作性质
						for (let i = 0; i < this.gzxz.length; i++) {
							if (this.gzxz[i].enumValue == this.jobForm.type) {
								this.gzxzIndex = i //默认选项
								this.jobForm.type = this.gzxz[i].enumValue
							}
						}

					}
				})
			}
		}
	}
</script>

<style lang="scss" scoped>
	.activeFalse {
		color: #000000;
	}

	.activeTrue {
		color: red;
	}

	.main {
		position: absolute;
		top: 0;
		z-index: 999;
		width: 100%;
		background: #f7f7f7;
		height: 100%;

		.joinReleamain {
			display: flex;
			flex-direction: column;


			image {
				width: 14rpx;
				height: 22rpx;
			}

			.joinReleamainList {
				    padding: 0 70rpx;
				    box-sizing: border-box;
				    background: #ffffff;
				    margin: 10rpx 0;
				    position: relative;

				text {
					display: block;
					margin: 30rpx 0;
				}

				>textarea {
					height: 150rpx;
					padding: 0 10rpx;

				}
				input{
					padding: 0 10rpx;
				}

				.zc_line {
					width: 670rpx;
					height: 1rpx;
					background: #e5e5e5;
					margin-top: 20rpx;
				}

				.common_line {
					position: absolute;
					    width: 603rpx;
					    height: 100%;
					picker {
						    width: 100%;
						    text-align: right;
						    height: 100%;
						    display: flex;
						    flex-direction: column;
						    justify-content: center;
					}

					text {
						display: block;
						width: 14rpx;
						color: #c0c3c8;
						margin: 0 5rpx;
					}
				}

				.selectCerts {

					text {
						width: 100%;
						text-align: right;
					}
				}

				.titStyle {
					font-size: 33rpx;
					font-family: Microsoft YaHei Bold, Microsoft YaHei Bold-Bold;
					font-weight: bold;
					text-align: left;
					color: #49b3af;
				}
			}

			.joinReleamainBtn {
				width: 600rpx;
				height: 88rpx;
				line-height: 88rpx;
				text-align: center;
				background: #5cd1ce;
				border-radius: 44rpx;
				color: #ffffff;
				margin: 50rpx auto;
			}
		}
	}

	.nameClass {
		width: 565rpx;
	}
</style>
